package com.htc.android.footprints;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.ContentObserver;
import android.graphics.drawable.Drawable;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.htc.android.footprints.activity.FootprintCamera;
import com.htc.android.footprints.activity.FootprintDetailEditActivity;
import com.htc.android.footprints.activity.ListModeNewActivity;
import com.htc.android.footprints.service.LocationAgentService;
import com.htc.android.footprints.utils.FootprintUtils;
import com.htc.android.footprints.utils.StorageUtil;
import com.htc.android.footprints.vo.Footprint;

public class FootprintsMainActivity extends Activity
{
  public static final int MENU_CREATE = 2;
  public static final int MENU_DELETE = 4;
  public static final int MENU_EDIT = 1;
  public static final int MENU_EXPORT = 3;
  public static final int MENU_LIST = 0;
  public static final int MENU_SETTING = 5;
  private static final int PROGRESS_DIALOG = 0;
  private static final int REQUEST_CHECK_SDCARD = 0;
  private static final String TAG = "FootprintsMainActivity";
  View addNewTap;
  long end;
  private ServiceConnection mConnection = new ServiceConnection()
  {
    public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
    {
      Log.i("FootprintsMainActivity", "onServiceConnected");
      FootprintsMainActivity.this.mService = ILocationAgentService.Stub.asInterface(paramIBinder);
    }

    public void onServiceDisconnected(ComponentName paramComponentName)
    {
      FootprintsMainActivity.this.mService = null;
    }
  };
  private ContentObserver mObserver;
  ILocationAgentService mService = null;
  private StorageUtil mStorageUtil;
  private StepListView photoPanel;
  long start;
  private TaskBar taskBar;

  private void checkEmpty()
  {
    if (this.addNewTap == null)
    {
      this.addNewTap = LayoutInflater.from(this).inflate(2130903041, null);
      this.addNewTap.setOnClickListener(new View.OnClickListener()
      {
        public void onClick(View paramView)
        {
          Intent localIntent = new Intent(FootprintsMainActivity.this, FootprintCamera.class);
          FootprintsMainActivity.this.startActivity(localIntent);
        }
      });
    }
    if ((this.photoPanel != null) && (this.photoPanel.isEmpty()))
      if (this.addNewTap.getParent() == null)
      {
        RelativeLayout localRelativeLayout = (RelativeLayout)findViewById(2131492990);
        RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
        localLayoutParams.addRule(10, -1);
        localLayoutParams.addRule(14, -1);
        localLayoutParams.topMargin = 10;
        localRelativeLayout.addView(this.addNewTap, localLayoutParams);
      }
    while (true)
    {
      return;
      if (this.addNewTap.getParent() != null)
      {
        ((RelativeLayout)findViewById(2131492990)).removeView(this.addNewTap);
        continue;
      }
    }
  }

  private void checkLocationSetting()
  {
    if (!((LocationManager)getSystemService("location")).isProviderEnabled("gps"))
      new AlertDialog.Builder(this).setIcon(17301543).setTitle(2131361795).setMessage(2131361904).setPositiveButton(17039379, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          Intent localIntent = new Intent("android.settings.LOCATION_SOURCE_SETTINGS");
          FootprintsMainActivity.this.startActivity(localIntent);
          paramDialogInterface.dismiss();
        }
      }).setNegativeButton(17039369, new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramDialogInterface, int paramInt)
        {
          paramDialogInterface.dismiss();
        }
      }).create().show();
  }

  void initTaskBar()
  {
    this.taskBar = ((TaskBar)findViewById(2131492989));
    this.taskBar.init(2);
    this.taskBar.setUpText(getString(2131361889));
    this.taskBar.setCountIndicatorVisibility(4);
    TaskBar localTaskBar1 = this.taskBar;
    Drawable localDrawable1 = getResources().getDrawable(2130837653);
    localTaskBar1.setIcon(localDrawable1, 0);
    TaskBar localTaskBar2 = this.taskBar;
    Drawable localDrawable2 = getResources().getDrawable(2130837654);
    localTaskBar2.setIcon(localDrawable2, 2);
    this.taskBar.setOnClickListener(new TaskBar.OnPanelClickListener()
    {
      public void onCenterClick()
      {
      }

      public void onLeftClick()
      {
        Intent localIntent = new Intent("com.htc.android.footprints.ListModeActivity");
        FootprintsMainActivity.this.startActivity(localIntent);
      }

      public void onRightClick()
      {
        Intent localIntent = new Intent(FootprintsMainActivity.this, FootprintCamera.class);
        FootprintsMainActivity.this.startActivity(localIntent);
      }
    });
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    this.start = SystemClock.elapsedRealtime();
    getWindow().setBackgroundDrawable(null);
    checkLocationSetting();
    setVolumeControlStream(3);
    requestWindowFeature(1);
    long l = SystemClock.elapsedRealtime();
    setContentView(2130903065);
    Log.d("Sam", "setContentView  time " + (SystemClock.elapsedRealtime() - l));
    initTaskBar();
    this.photoPanel = ((StepListView)findViewById(2131492988));
    this.photoPanel.setTaskBar(this.taskBar);
    this.mObserver = new ContentObserver(new Handler())
    {
      public void onChange(boolean paramBoolean)
      {
        FootprintsMainActivity.this.checkEmpty();
      }
    };
    this.photoPanel.registerContentObserver(this.mObserver);
    this.mStorageUtil = new StorageUtil(getApplicationContext());
    this.mStorageUtil.SetOnChangeStorageListerner(new StorageUtil.OnChangeStorageListener()
    {
      public void onStorageChanged(int paramInt)
      {
        Intent localIntent;
        if ((paramInt > 1) && (!StorageUtil.hasExternalStorage()))
        {
          localIntent = new Intent("SDCardConfirmDialog");
          if (!StorageUtil.isMediaShared())
            break label55;
          localIntent.putExtra("DATA", FootprintsMainActivity.this.getResources().getString(2131361955));
        }
        while (true)
        {
          FootprintsMainActivity.this.startActivity(localIntent);
          return;
          label55: localIntent.putExtra("DATA", FootprintsMainActivity.this.getResources().getString(2131361896));
        }
      }
    });
    Log.d("Sam", "oncreate time " + (SystemClock.elapsedRealtime() - this.start));
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    default:
    case 0:
    }
    ProgressDialog localProgressDialog;
    for (Object localObject = null; ; localObject = localProgressDialog)
    {
      return localObject;
      localProgressDialog = new ProgressDialog(this);
      localProgressDialog.setTitle(getResources().getString(2131361861));
      localProgressDialog.setMessage(getResources().getString(2131361905));
      localProgressDialog.setIndeterminate(true);
      localProgressDialog.setCancelable(false);
    }
  }

  public boolean onCreateOptionsMenu(Menu paramMenu)
  {
    paramMenu.add(0, 0, 0, getResources().getString(2131361862)).setIcon(2130837728);
    paramMenu.add(0, 1, 1, getResources().getString(2131361807)).setIcon(2130837680);
    paramMenu.add(0, 2, 2, getResources().getString(2131361832)).setIcon(2130837694);
    paramMenu.add(0, 3, 3, getResources().getString(2131361825)).setIcon(2130837680);
    paramMenu.add(0, 4, 4, getResources().getString(2131361808)).setIcon(2130837678);
    return true;
  }

  protected void onDestroy()
  {
    super.onDestroy();
    if (this.addNewTap != null)
    {
      this.addNewTap.setOnClickListener(null);
      this.addNewTap.getBackground().setCallback(null);
      this.addNewTap = null;
    }
    this.photoPanel.unregisterContentObserver(this.mObserver);
    try
    {
      if (this.mService.isTracking())
        this.mService.shutdownAgent();
      this.mStorageUtil.SetOnChangeStorageListerner(null);
      this.mStorageUtil = null;
      this.photoPanel.release();
      ((ViewGroup)this.photoPanel.getParent()).removeAllViews();
      this.photoPanel = null;
      this.taskBar.setOnClickListener((TaskBar.OnPanelClickListener)null);
      this.taskBar.getLeftButton().getDrawable().setCallback(null);
      this.taskBar.getLeftButton().setImageDrawable(null);
      this.taskBar.getRightButton().getDrawable().setCallback(null);
      this.taskBar.getRightButton().setImageDrawable(null);
      this.taskBar = null;
      return;
    }
    catch (RemoteException localRemoteException)
    {
      while (true)
        Log.d("FootprintsMainActivity", localRemoteException.getMessage(), localRemoteException);
    }
  }

  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 4);
    try
    {
      this.mService.shutdownAgent();
      return super.onKeyDown(paramInt, paramKeyEvent);
    }
    catch (RemoteException localRemoteException)
    {
      while (true)
        localRemoteException.printStackTrace();
    }
  }

  public boolean onOptionsItemSelected(MenuItem paramMenuItem)
  {
    if (paramMenuItem.getItemId() == 0)
    {
      Intent localIntent1 = new Intent();
      localIntent1.setClass(this, ListModeNewActivity.class);
      startActivity(localIntent1);
    }
    while (true)
    {
      for (int i = 0; ; i = 0)
      {
        return i;
        if (paramMenuItem.getItemId() == 1)
        {
          Intent localIntent2 = new Intent();
          localIntent2.putExtra("DATA", this.photoPanel.getCurrentFootprint());
          localIntent2.setClass(this, FootprintDetailEditActivity.class);
          startActivity(localIntent2);
          break;
        }
        if (paramMenuItem.getItemId() == 2)
        {
          Intent localIntent3 = new Intent();
          localIntent3.setClass(this, FootprintCamera.class);
          startActivity(localIntent3);
          break;
        }
        if (paramMenuItem.getItemId() == 4)
        {
          if (this.photoPanel.isEmpty())
            break;
          Footprint localFootprint2 = this.photoPanel.getCurrentFootprint();
          new HtcAlertDialog.Builder(this).setTitle(getString(2131361957)).setMessage(getString(2131361815)).setPositiveButton(getString(2131361893), new DialogInterface.OnClickListener(localFootprint2)
          {
            public void onClick(DialogInterface paramDialogInterface, int paramInt)
            {
              paramDialogInterface.dismiss();
              FootprintUtils.deleteFootprint(FootprintsMainActivity.this.getApplicationContext(), this.val$footprint);
              FootprintsMainActivity.this.photoPanel.deleteCurrent();
              new Handler().postDelayed(new Runnable()
              {
                public void run()
                {
                  FootprintsMainActivity.this.checkEmpty();
                }
              }
              , 500L);
            }
          }).setNegativeButton(getString(2131361796), new DialogInterface.OnClickListener()
          {
            public void onClick(DialogInterface paramDialogInterface, int paramInt)
            {
              paramDialogInterface.dismiss();
            }
          }).show();
          break;
        }
        if (paramMenuItem.getItemId() != 3)
          break label324;
        if (StorageUtil.isExternalStorageEnough(59300L))
          break label270;
        FootprintUtils.showToast(this, getResources().getString(2131361887));
      }
      label270: if (this.photoPanel.isEmpty())
        continue;
      Footprint localFootprint1 = this.photoPanel.getCurrentFootprint();
      Footprint[] arrayOfFootprint = new Footprint[1];
      arrayOfFootprint[0] = localFootprint1;
      FootprintUtils.exportKMZ(this, localFootprint1.mName.replace(" ", "_"), arrayOfFootprint);
      continue;
      label324: if (paramMenuItem.getItemId() != 5)
        continue;
      Intent localIntent4 = new Intent("ImportDialog");
      localIntent4.putExtra("import_data", new Footprint());
      startActivity(localIntent4);
    }
  }

  protected void onPause()
  {
    super.onPause();
    if (this.mStorageUtil != null)
      this.mStorageUtil.closeStorgaeUtil();
    if (!this.photoPanel.isEmpty())
    {
      SharedPreferences.Editor localEditor = getSharedPreferences("Footprints", 0).edit();
      localEditor.putInt("FOOTPRINTS_COUNT", this.photoPanel.getCount());
      localEditor.commit();
    }
    unbindService(this.mConnection);
  }

  protected void onPostResume()
  {
    super.onPostResume();
    this.end = SystemClock.elapsedRealtime();
    Log.d("Sam", "init tim " + (this.end - this.start));
  }

  public boolean onPrepareOptionsMenu(Menu paramMenu)
  {
    MenuItem localMenuItem1 = paramMenu.getItem(0);
    boolean bool1;
    boolean bool2;
    label50: boolean bool3;
    label82: MenuItem localMenuItem4;
    if (!this.photoPanel.isEmpty())
    {
      bool1 = true;
      localMenuItem1.setEnabled(bool1);
      MenuItem localMenuItem2 = paramMenu.getItem(4);
      if (this.photoPanel.isEmpty())
        break label131;
      bool2 = true;
      localMenuItem2.setEnabled(bool2);
      MenuItem localMenuItem3 = paramMenu.getItem(1);
      if (this.photoPanel.isEmpty())
        break label137;
      bool3 = true;
      localMenuItem3.setEnabled(bool3);
      localMenuItem4 = paramMenu.getItem(3);
      if (this.photoPanel.isEmpty())
        break label143;
    }
    label131: label137: label143: for (boolean bool4 = true; ; bool4 = false)
    {
      localMenuItem4.setEnabled(bool4);
      return true;
      bool1 = false;
      break;
      bool2 = false;
      break label50;
      bool3 = false;
      break label82;
    }
  }

  protected void onResume()
  {
    super.onResume();
    long l = SystemClock.elapsedRealtime();
    this.photoPanel.setBackgroundResource(2130837584);
    this.taskBar.setVisibility(0);
    if (getSharedPreferences("Footprints", 0).getInt("FOOTPRINTS_COUNT", 0) != this.photoPanel.getCount())
      this.photoPanel.setSelection(0);
    if (this.mStorageUtil != null)
      this.mStorageUtil.startStorageUtil();
    Intent localIntent1;
    if (!StorageUtil.hasExternalStorage())
    {
      localIntent1 = new Intent("SDCardConfirmDialog");
      if (!StorageUtil.isMediaShared())
        break label209;
      localIntent1.putExtra("DATA", getResources().getString(2131361955));
    }
    while (true)
    {
      startActivity(localIntent1);
      Intent localIntent2 = new Intent();
      localIntent2.setClass(getApplicationContext(), LocationAgentService.class);
      bindService(localIntent2, this.mConnection, 1);
      new Handler().postDelayed(new Runnable()
      {
        public void run()
        {
          FootprintsMainActivity.this.checkEmpty();
        }
      }
      , 500L);
      Log.d("Sam", "resume time " + (SystemClock.elapsedRealtime() - l));
      return;
      label209: localIntent1.putExtra("DATA", getResources().getString(2131361896));
    }
  }
}

/* Location:           E:\workspace\dex2java\dex-translator-0.0.9.3\HtcFootprints_dex2jar.jar
 * Qualified Name:     com.htc.android.footprints.FootprintsMainActivity
 * JD-Core Version:    0.6.0
 */